package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

	@Autowired
	private BaseCategoryService baseCategoryService;

	/**
	 * 查询1.2.3级分类信息
	 * @return
	 */
	@GetMapping("/category/getBaseCategoryList")
	public Result<List<JSONObject>> getBaseCategoryList() {
		//从yapi文档看接口信息 返回值类型为Objct[]集合类型 集合类型里面又包含了map集合
		//JSONObject底层是Map集合 同时又提供了多个api可以操作map对象
		List<JSONObject>list = baseCategoryService.getBaseCategoryList();
		return Result.ok(list);

	}

	/**
	 * 根据一级分类id获取所有的属性值供选择
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类Id获取分类属性列表")
	@GetMapping("/category/findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> getAttributesByCategory1Id(@PathVariable Long category1Id){
		List<BaseAttribute>baseAttributeList = baseCategoryService.getAttributesByCategory1Id(category1Id);
		//因为attribute实体类里面已经封装了attributeList的属性集合 所以可以直接把attribute作为返回值
		return Result.ok(baseAttributeList);
	}

}

